package cn.usian.controller;


import cn.usian.jyzx.model.dto.h5.ProductSkuDto;
import cn.usian.jyzx.model.entity.product.Brand;
import cn.usian.jyzx.model.entity.product.Category;
import cn.usian.jyzx.model.entity.product.ProductSku;
import cn.usian.jyzx.model.vo.common.Result;
import cn.usian.jyzx.model.vo.common.ResultCodeEnum;
import cn.usian.jyzx.model.vo.h5.ProductItemVo;
import cn.usian.service.BrandService;
import cn.usian.service.CategoryService;
import cn.usian.service.ProductService;
import cn.usian.service.ProductSkuService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/product")
@Tag(name = "首页接口")
public class ProductController {
    @Autowired
    ProductService productService;
    @Autowired
    BrandService brandService;
    @Autowired
    ProductSkuService productSkuService;
    @Autowired
    CategoryService categoryService;

    @GetMapping("index")
    @Operation(summary = "首页信息")
    public Result all(){
        return productService.findAll();
    }

    @GetMapping("category/findCategoryTree")
    public Result<List<Category>> findCategoryTree(){
        List<Category> categoryList=categoryService.findCategoryTree();
        return Result.build(categoryList, ResultCodeEnum.SUCCESS);
    }


    @GetMapping(value = "/{page}/{limit}")
    public Result<PageInfo<ProductSkuDto>> productSkuDtoPageInfo(@PathVariable Integer page,@PathVariable Integer limit,ProductSkuDto productSkuDto){
        return productService.productSkuDtoPageInfo(page,limit,productSkuDto);
    }

    @RequestMapping("/brand/findAll")
    public Result<List<Brand>> resultbrand(){
        return brandService.findAll();
    }

    @RequestMapping("/item/{id}")
    public Result<ProductItemVo> item(@PathVariable Long id){
        return productService.item(id);
    }


    @RequestMapping("/findById/{id}")
    public ProductSku findById(@PathVariable Long id){
        return productSkuService.findById(id);
    }

}
